/* GUI CONVERTED from reconv2.p (converter v1.76) Mon Sep 17 06:38:09 2001 */
/* reconv2.p - REPETITIVE                                                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.1.9 $                                                       */
/* REVISION: 7.3      LAST MODIFIED: 05/01/95   BY: WUG *G0LV*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane     */
/* REVISION: 9.1      LAST MODIFIED: 05/22/00 BY: *N08Y* Kaustubh K.          */
/* REVISION: 9.1      LAST MODIFIED: 05/31/00 BY: *N09M* Inna Lyubarsky       */
/* REVISION: 9.1      LAST MODIFIED: 07/10/00 BY: *N0FD* Inna Lyubarsky       */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* Mark Brown           */
/* Revision: 1.5.1.7      BY: Niranjan R.       DATE: 07/13/01  ECO: *P00L*   */
/* $Revision: 1.5.1.9 $   BY: Jean Miller       DATE: 09/14/01  ECO: *N128*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=Report                                                       */

/*!
   Program to read the captured wip balance data
   and load into the new Repetitive via WIP Adjust transactions
*/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reconv2_p_6 "Effective"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable i as integer.
define variable eff_date as date label {&reconv2_p_6}.
define variable cumwo_lot as character.
define variable trans_type as character.
define variable ophist_recid as recid.
define variable new_inque_qty as decimal.
define variable qty_inque_adj as decimal.
define variable prev_op as integer.

define variable dftWVARAcct       like pl_wvar_acct no-undo.
define variable dftWVARSubAcct    like pl_wvar_sub  no-undo.
define variable dftWVARCostCenter like pl_wvar_cc   no-undo.
define variable msg-text          as character format "x(45)".

define buffer newrep_wr_route for wr_route.
define buffer qadwkfl for qad_wkfl.



/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
eff_date colon 30
with frame a side-labels attr-space width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

find first qadwkfl where qad_key1 = "repwipbals" no-lock no-error.

if available qadwkfl then do:
   if qadwkfl.qad_charfld[3] = "x" then do:
      /* THIS FUNCTION HAS BEEN RUN ALREADY */
      {pxmsg.i &MSGNUM=3814 &ERRORLEVEL=2}
      message.
      message.
   end.
end.
else do:
   /* THERE ARE NO WIP BALANCE RECORDS */
   {pxmsg.i &MSGNUM=3813 &ERRORLEVEL=4}
   message.
   message.
   leave.
end.

find mfc_ctrl where mfc_field = "rpc_using_new" no-lock no-error.

if available mfc_ctrl and mfc_logical = false then do:
   /* NEW REPETITIVE IS NOT ENABLED. USE 18.22.24 REREPM.P */
   {pxmsg.i &MSGNUM=3837 &ERRORLEVEL=4}
   message.
   message.
   undo, leave.
end.

eff_date = today.

repeat:

   update eff_date with frame a.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   for each qadwkfl no-lock
      where qadwkfl.qad_key1 = "repwipbals",
      each wo_mstr no-lock
      where wo_lot = qadwkfl.qad_charfld[1],
      each wr_route no-lock
      where wr_lot = qadwkfl.qad_charfld[1]
        and wr_op = integer(qadwkfl.qad_charfld[2])
   break by wo_site by wo_part by wo_line by wo_routing by wo_bom_code
   by wr_lot by wr_op:

      if first-of(wr_lot) then do:

         {gprun.i ""regetwo.p""
            "(input wo_site, input wo_part, input eff_date,
              input wo_line, input wo_routing, input wo_bom_code,
              output cumwo_lot)"}

         if cumwo_lot = ? then do:
            {gprun.i ""recrtwo.p""
               "(input wo_site, input wo_part, input eff_date,
                 input wo_line, input wo_routing, input wo_bom_code,
                 output cumwo_lot)"}
         end.

      end.

      /* NEED TO ENSURE THERE IS A CORRESPONDING OP IN THE NEW CUMWO */
      /* AND THAT IT IS NOT THE FIRST OP. */

      do for newrep_wr_route:

         find newrep_wr_route
            where wr_lot = cumwo_lot
              and wr_op = wr_route.wr_op
         no-lock no-error.

         if available newrep_wr_route then do:

            new_inque_qty = wr_qty_inque.

            find last newrep_wr_route
               where wr_lot = cumwo_lot
                 and wr_op < wr_route.wr_op
            no-lock no-error.

            if available newrep_wr_route then do:

               prev_op = wr_op.

               find pt_mstr where pt_part = wo_part no-lock.
               find pl_mstr where pl_prod_line = pt_prod_line no-lock.

              {gprun.i ""glactdft.p""
                 "(input ""WO_WVAR_ACCT"",
                   input pt_prod_line,
                   input wo_site,
                   input """",
                   input """",
                   input no,
                   output dftWVARAcct,
                   output dftWVARSubAcct,
                   output dftWVARCostCenter)"}

               qty_inque_adj = qadwkfl.qad_decfld[5] - new_inque_qty.

               /* FOR THE INPUT QUEUE, WE MOVE THE NEW ADJUSTMENT QTY BACK TO */
               /* THE PRIOR OP OUTPUT QUEUE AND ADJUST IT THERE IT THERE*/

               trans_type = "WIPADJ-I".

               {gprun.i ""reophist.p""
                  "(input trans_type, input cumwo_lot, input prev_op,
                    input """", input wr_wkctr, input wr_mch, input """",
                    input """", input eff_date, output ophist_recid)"}

               {gprun.i ""removea.p""
                  "(input cumwo_lot, input prev_op,
                    input eff_date, input ophist_recid, input qty_inque_adj)"}

               /* REPLACED pl_wvar_acct, pl_wvar_sub and pl_wvar_cc WITH */
               /* dftWVARAcct, dftWVARSubAcct and dftWVARCostCenter      */
               {gprun.i ""rewadja.p""
                  "(input cumwo_lot, input prev_op, input dftWVARAcct,
                    input dftWVARSubAcct,
                    input dftWVARCostCenter,
                    input qty_inque_adj, input """",
                    input yes, input """", input ophist_recid)"}

               /* Adjusted input queue qty in cum order */
               {pxmsg.i &MSGNUM=4862 &ERRORLEVEL=1 &MSGBUFFER=msg-text}

               put
                  msg-text format "x(48)"
                  space
                  cumwo_lot space
                  {gplblfmt.i &FUNC=getTermLabel(""OPERATION"",12)
                              &CONCAT="':'"}
                  space
                  wr_route.wr_op space
                  {gplblfmt.i &FUNC=getTermLabel(""SITE"",8) &CONCAT="':'"}
                  space
                  wo_site space
                  {gplblfmt.i &FUNC=getTermLabel(""ITEM"",8) &CONCAT="':'"}
                  space
                  wo_part space
                  {gplblfmt.i &FUNC=getTermLabel(""ADJUSTED_QUANTITY"",9)
                              &CONCAT="':'"}
                  space
                  qty_inque_adj
                  skip.

            end.

            else do:

               /* First op in new cum order */
               {pxmsg.i &MSGNUM=4860 &ERRORLEVEL=2 &MSGBUFFER=msg-text}

               put
                  msg-text format "x(43)"
                  space
                  wr_route.wr_lot space
                  {gplblfmt.i &FUNC=getTermLabel(""OPERATION"",12)
                              &CONCAT="':'"}
                  space
                  wr_route.wr_op space
                  {gplblfmt.i &FUNC=getTermLabel(""SITE"",8) &CONCAT="':'"}
                  space
                  wo_site space
                  {gplblfmt.i &FUNC=getTermLabel(""ITEM"",8) &CONCAT="':'"}
                  space
                  wo_part space
                  {gplblfmt.i &FUNC=getTermLabel(""WIP_NOT_TRANSFERRED"",25)}
                  skip.

            end.

         end.

         else do:

            /* No corresponding op in cum order */
            {pxmsg.i &MSGNUM=4861 &ERRORLEVEL=2 &MSGBUFFER=msg-text}

            put
               msg-text format "x(52)"
               space
               wr_route.wr_lot space
               {gplblfmt.i &FUNC=getTermLabel(""OPERATION"",12)
                           &CONCAT="':'"}
               space
               wr_route.wr_op space
               {gplblfmt.i &FUNC=getTermLabel(""SITE"",8) &CONCAT="':'"}
               space
               wo_site space
               {gplblfmt.i &FUNC=getTermLabel(""ITEM"",8) &CONCAT="':'"}
               space
               wo_part space
               {gplblfmt.i &FUNC=getTermLabel(""WIP_NOT_TRANSFERRED"",25)}
               skip.

         end.

      end.

   end.

   for each qadwkfl where qadwkfl.qad_key1 = "repwipbals"
   exclusive-lock:
      qadwkfl.qad_charfld[3] = "x".
   end.

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


end.
